//
//  BargainTableViewModel.m
//  quxiangtao
//
//  Created by E人一铺 on 2019/2/27.
//  Copyright © 2019年 shanhaijin. All rights reserved.
//

#import "BargainTableViewModel.h"

@implementation BargainTableViewModel

+ (void)buyOrderContentModelWithPage:(NSInteger)page buyType:(NSString *)type successBlock:(HttpRequestSuccess)successBlock failBlock:(HttpRequestFailed)failBlock {
    
    NSString *url = @"";
    
    if ([type intValue] == 1) { // 砍价
        url = @"bargain/bargaingoods/bargainApp";
    }else if ([type intValue] == 5){
        
    }else { // 拼团
        url = @"groupbuy/groupbuy/mySpellOrder";
    }
    
    NSString *str = [NSString stringWithFormat:@"{\"type\" : \"%@\", \"userid\" : \"%@\", \"page\" : \"%@\", \"pageSize\" : \"%@\"}", [RSA encryptString:type publicKey:PublicKey], [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%zd", page] publicKey:PublicKey], [RSA encryptString:@"10" publicKey:PublicKey]];
    
    [PPNetworkHelper POST:url parameters:@{@"json" : str} success:^(id responseObject) {
        
   
        NSLog(@"拼团中订单列表：%@", responseObject);
        
        NSArray *array = [NSArray arrayWithArray:responseObject[@"data"]];
        
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:responseObject];
        
        if (array.count > 0) {
            
            NSArray *modelArr = [BargainTableViewModel mj_objectArrayWithKeyValuesArray:array];
            
            [dict removeObjectForKey:@"data"];
            [dict setObject:modelArr forKey:@"data"];
        }
        
        if (successBlock) {
            
            successBlock(dict);
        }
        
    } failure:^(NSError *error) {
        
        if (failBlock) {
            
            failBlock(error);
        }
    }];
    
}

@end
